package com.hwh.trafficdemo.controller;

import com.hwh.trafficdemo.dao.IAppInfoDao;
import com.hwh.trafficdemo.entity.AppInfo;
import com.hwh.trafficdemo.entity.BusDomJson;
import com.hwh.trafficdemo.utils.BusUtils.BusData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
public class BusInfoController {


    @Autowired
    BusData busData;

    @Autowired
    IAppInfoDao appInfoDao;

    @GetMapping("/getBusInfo/{busRouteName}/{stopName}")
    @ResponseBody
    public BusDomJson getBusInfo(@PathVariable("busRouteName") String busRouteName,@PathVariable("stopName") String stopName){

        BusDomJson allBusData = busData.getAllBusData(busRouteName, stopName);
        return allBusData;
    }

    @GetMapping("/version")
    @ResponseBody
    public String getAppVersion(){
        Map<String,Object> map = new HashMap<>();
        String appVersion = appInfoDao.getAppVersion("fafubus");
        return appVersion;
    }

    @PostMapping("/opinion")
    @ResponseBody
    public String saveOpinion(@RequestParam("version") String version,@RequestParam("opoinion") String opoinion){
        AppInfo appInfo = new AppInfo();
        appInfo.setAppName("fafubus-"+version);
        appInfo.setAppOpinion(opoinion);
        appInfo.setAppVersion(version);
        appInfoDao.savaOpinion(appInfo);
        return null;
    }
}
